package com.tzbank.wisdom.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.tzbank.wisdom.service.AIService;
import com.tzbank.wisdom.utils.BusinessConstant;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(tags={"AI转递接口"})
@RestController
public class AIController {
	
	@Autowired
    AIService aiService;
	
	/**	 人脸初始化认证
	 *     参数名
	 *    certName     ---身份证名字（String）
	 *    certNo       ---身份证号 （String）
	 *    setMetainfo  -- 设备的环境参数（String）集合形式
	 *    bizId        -- 唯一标识（后台生成）
	 *    userId       -- 用户id
	 * @param reqBody
	 * @return
	 * @throws InterruptedException
	 */
	@ApiOperation(value="intoface", notes="认证初始化--->[metainfo]该参数为必填项，其他参数暂时不需要填写！！")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "metainfo", value = "metainfo 环境参数，需要通过客户端 SDK 获取",paramType = "query",required = true),
			@ApiImplicitParam(name = "bizId", value = "接入方请求的唯一标识，由字母、数字、下划线组成，商户须确保其唯一性。",paramType = "query") ,
			@ApiImplicitParam(name = "externParam", value = "预留扩展业务参数",paramType = "query"),
			@ApiImplicitParam(name = "identityParam", value = "用户身份信息，由 JSON 字符串构成，目前支持大陆居民身份证，对应的 identityType 值为 CERT，certType 值为 IDCARD。",paramType = "query"),
			@ApiImplicitParam(name = "zimId", value = "刷脸认证唯一标识",paramType = "query"),
			@ApiImplicitParam(name = "certNo", value = "身份证号",paramType = "query"),
			@ApiImplicitParam(name = "userId", value = "用户id",paramType = "query"),
			@ApiImplicitParam(name = "certName", value = "身份证名字",paramType = "query")
		})
	@RequestMapping(value="/intoface", method=RequestMethod.POST)
    public Map<String,Object> intoface(@RequestBody Map<String,Object> reqBody) {
		String url = BusinessConstant.AI_FACE_SERVICE + BusinessConstant.INTO_FACE ;
		reqBody.put("requestSource", "ABP");
		return aiService.aiApply(reqBody, url);
    }
	
	/**
	 *  认证确认
	 * @param BizId
	 * @param ZimId
	 * @return
	 */
 	@ApiOperation(value="queryFace", notes="认证结果查询")
 	@ApiImplicitParams({
		@ApiImplicitParam(name = "metainfo", value = "metainfo 环境参数，需要通过客户端 SDK 获取",paramType = "query"),
		@ApiImplicitParam(name = "bizId", value = "接入方请求的唯一标识，由字母、数字、下划线组成，商户须确保其唯一性。",paramType = "query",required = true) ,
		@ApiImplicitParam(name = "externParam", value = "预留扩展业务参数",paramType = "query"),
		@ApiImplicitParam(name = "identityParam", value = "用户身份信息，由 JSON 字符串构成，目前支持大陆居民身份证，对应的 identityType 值为 CERT，certType 值为 IDCARD。",paramType = "query"),
		@ApiImplicitParam(name = "zimId", value = "刷脸认证唯一标识",paramType = "query",required = true),
		@ApiImplicitParam(name = "certNo", value = "身份证号",paramType = "query"),
		@ApiImplicitParam(name = "userId", value = "用户id",paramType = "query"),
		@ApiImplicitParam(name = "certName", value = "身份证名字",paramType = "query")
	})
 	@RequestMapping(value="/queryFace", method={RequestMethod.POST})
 	@ResponseBody
	public Map<String,Object> queryFace(@RequestBody Map<String,Object> reqBody){
 		String url = BusinessConstant.AI_FACE_SERVICE + BusinessConstant.QUERY_FACE ;
 		reqBody.put("requestSource", "ABP");
		return aiService.aiApply(reqBody, url);
 	}
 	
 	@ApiOperation(value="intovoice", notes="语音语义分析")
 	@ApiImplicitParams({
		@ApiImplicitParam(name = "auf", value = "音频格式（8k、16k）",paramType = "query",required = true),
		@ApiImplicitParam(name = "aue", value = "音频编码，可选值：raw",paramType = "query",required = true) ,
		@ApiImplicitParam(name = "scene", value = "情景模式",paramType = "query",required = true),
		@ApiImplicitParam(name = "spx_fsize", value = "speex 编码器对每帧音频（SPEEX_GET_FRAME_SIZE获取）进行编码压缩后的纯语音数据大小。",paramType = "query"),
		@ApiImplicitParam(name = "userid", value = "用户ID",paramType = "query",required = true),
		@ApiImplicitParam(name = "data", value = "Base64 编码的音频， 支持 pcm 或 wav 以及 speex 宽带压缩格式",paramType = "query",required = true),

	})
 	@RequestMapping(value="/intovoice",method = { RequestMethod.POST })
	@ResponseBody
	public Map<String,Object> intovoice( @RequestBody Map<String,Object> reqBody) {
 		String url = BusinessConstant.AI_VOICE_SERVICE + BusinessConstant.INTO_VOICE ;		//语音初始化地址		
 		reqBody.put("requestSource", "ABP");
		return aiService.aiApply(reqBody, url);
	}
 	
 	/**
 	 * 3.2指纹注册初始化
	 * 接口:alipay.security.prod.fingerprint.apply.initialize
 	 * @return 
	 * 业务参数:
			{		
				"auth_type": "1",
				"ifaa_version": "2.0" 				
			}
	 */
	@ApiOperation(value="fingerPrintApplyInitialize", notes="3.2 指纹注册初始化")
	@ApiImplicitParams({@ApiImplicitParam(name = "auth_type", value = "auth_type",paramType = "query",required = true),
						@ApiImplicitParam(name = "ifaa_version", value = "ifaa_version",paramType = "query",required = true)})
	@RequestMapping(value="/fingerPrintApplyInitialize",method = { RequestMethod.POST })
	@ResponseBody
	public Map<String,Object> FingerPrintApplyItialize(@RequestBody Map<String,Object> reqBody){
		String url = BusinessConstant.AI_SFINGERPRINT_SERVICE + BusinessConstant.FINGERPRINT_APPLY_INITIALIZE ;
		reqBody.put("requestSource", "ABP");
		return aiService.aiApply(reqBody, url);
	}
	
	/**
	 * 3.3指纹注册接口
	 * 接口:alipay.security.prod.fingerprint.apply
	 * @return 
	 * 业务参数:
			{	
				"ifaf_message": "", //TA 返回的指纹注册消息,json字符  
				"out_biz_no": "20161126200040011100190086557102",
				"ifaa_version": "2.0"			
			}
	 */ 
	@ApiOperation(value="fingerPrintApply", notes="3.3 指纹注册接口")
	@ApiImplicitParams({@ApiImplicitParam(name = "ifaf_message", value = "TA返回的指纹注册消息,json字符",paramType = "query",required = true),
						@ApiImplicitParam(name = "out_biz_no", value = "out_biz_no",paramType = "query",required = true),
						@ApiImplicitParam(name = "ifaa_version", value = "ifaa_version",paramType = "query",required = true)})
	@RequestMapping(value="/fingerPrintApply",method = { RequestMethod.POST })
	@ResponseBody
	public Map<String,Object> FingerPrintApply(@RequestBody Map<String,Object> reqBody){		
		String url = BusinessConstant.AI_SFINGERPRINT_SERVICE + BusinessConstant.FINGERPRINT_APPLY;
		reqBody.put("requestSource", "ABP");
		return aiService.aiApply(reqBody, url);
	}
	
	/**
	 * 3.4指纹校验初始化接口
	 * 接口:alipay.security.prod.fingerprint.verify.initialize
	 * @return 
	 * 业务参数:
		{		
			"token": "96d559c6-cf9b-4b5e-bba7-1e040b4c28c9",
			"ifaa_version": "2.0"
		}
	 */
	@ApiOperation(value="fingerPrintVerifyInitialize", notes="3.4 指纹校验初始化接口")
	@ApiImplicitParams({@ApiImplicitParam(name = "token", value = "token",paramType = "query",required = true),
						@ApiImplicitParam(name = "ifaa_version", value = "ifaa_version",paramType = "query",required = true)})
	@RequestMapping(value="/fingerPrintVerifyInitialize",method = { RequestMethod.POST })
	public Map<String,Object> FingerPrintVerifyInitialize(@RequestBody Map<String,Object> reqBody) {		
		String url = BusinessConstant.AI_SFINGERPRINT_SERVICE + BusinessConstant.FINGERPRINT_VERIFY_INITIALIZE;
		reqBody.put("requestSource", "ABP");
		return aiService.aiApply(reqBody, url);
	}
	
	/**
	 * 3.5指纹校验接口
	 * 接口:alipay.security.prod.fingerprint.verify
	 * @return 
	 * 业务参数: 
	        {				
				"ifaf_message": "", //TA 校验后的ifaa_message
				"out_biz_no": "20161126200040011100190086557102", 
				"ifaa_version": "2.0",
				"needAuthData": true,
				"subAction": "update"
			}
	 */
	@ApiOperation(value="fingerPrintVerify", notes="3.5 指纹校验接口")
	@ApiImplicitParams({@ApiImplicitParam(name = "ifaf_message", value = "ifaf_message",paramType = "query",required = true),
						@ApiImplicitParam(name = "out_biz_no", value = "out_biz_no",paramType = "query",required = true),
						@ApiImplicitParam(name = "ifaa_version", value = "ifaa_version",paramType = "query",required = true),
						@ApiImplicitParam(name = "needAuthData", value = "needAuthData",paramType = "query",required = true),
						@ApiImplicitParam(name = "subAction", value = "subAction",paramType = "query",required = true)
	})	
	@RequestMapping(value="/fingerPrintVerify",method = { RequestMethod.POST })	
	public Map<String,Object> FingerPrintVerify(@RequestBody Map<String,Object> reqBody) {		
		String url = BusinessConstant.AI_SFINGERPRINT_SERVICE + BusinessConstant.FINGERPRINT_VERIFY;
		reqBody.put("requestSource", "ABP");
		return aiService.aiApply(reqBody, url);
	}
	/**
	 * 3.6 指纹注销接口
	 * 接口:alipay.security.prod.fingerprint.delete
	 * @return 
	 * @throws AlipayApiException
	 * 业务参数:
			{
				"token": "96d559c6-cf9b-4b5e-bba7-1e040b4c28c9",
				"ifaa_version": "2.0"
			}
	 */
	@ApiOperation(value="fingerPrintDelete", notes="3.6 指纹注销接口")
	@ApiImplicitParams({@ApiImplicitParam(name = "token", value = "token信息",paramType = "query",required = true),
					   	@ApiImplicitParam(name = "ifaa_version", value = "ifaa版本号",paramType = "query",required = true)
					  })	
	@RequestMapping(value="/fingerPrintDelete",method = { RequestMethod.POST })	
	public Map<String,Object> FingerPrintDelete(@RequestBody Map<String,Object> reqBody) {
		String url = BusinessConstant.AI_SFINGERPRINT_SERVICE + BusinessConstant.FINGERPRINT_DELETE;
		reqBody.put("requestSource", "ABP");
		return aiService.aiApply(reqBody, url);
	}
	
	/**
	 * 	传入识别类型，和文件类型
	 * @param type
	 * @param file
	 * @auther llz&wdj 2018/05/17
	 * @return
	 * 	02-二代证正面
		03-二代证反面
		17-银行卡
	 */
	@ApiOperation(value="intoOcr", notes="OCR识别")
	@ApiImplicitParams({@ApiImplicitParam(name = "type", value = "文件类型",paramType = "query",required = true),
					   	@ApiImplicitParam(name = "file", value = "文件",paramType = "query",required = true)
					  })	
	@RequestMapping(value="/intoOcr", method=RequestMethod.POST)
	public Map<String, Object> intoOcr(@RequestBody Map<String,Object> reqBody) {
		String url = BusinessConstant.AI_OCR_SERVICE + BusinessConstant.INTO_OCR;
		reqBody.put("requestSource", "ABP");
		return aiService.aiApply(reqBody, url);
	}
}
